<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="../css/pintuer.css">
<link rel="stylesheet" href="../css/admin.css">
<script src="../js/jquery.js"></script>
<script src="../js/pintuer.js"></script>
    <link href="../umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="../umeditor/third-party/jquery.min.js"></script>
    <script type="text/javascript" src="../umeditor/third-party/template.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../umeditor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="../umeditor/umeditor.min.js"></script>
    <script type="text/javascript" src="../umeditor/lang/zh-cn/zh-cn.js"></script>
</head>
<script type="text/javascript">
	$(function(){
		
		$(".button").click(function(){
			
			if($(".button").text().indexOf("修改")!=-1){
				//alert($(".button").text());
				$(".form-x")[0].action="${ctx }/post/update";
			}
		});
		
		
		$.post("${ctx}/postType/findPostType", function(data, status, xhr){
			callback(data);
		},'json');
		
		function callback(data){
			var tId = $("#tId").val();
			for(var i=0;i<data.length;i++){
				if(tId==data[i].id){
					$("#typeId").prepend("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
				}else{
					$("#typeId").append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
				}
				//prepend
				
			}
		}
	})
	
</script>
<body>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o">
  </span>
  <c:if test="${empty post}">
  	增加文章内容
  </c:if>	
  <c:if test="${!empty post}">
  	 修改文章内容
  </c:if>	
  </strong>
  </div>
  <div class="body-content">
    <form method="post" class="form-x" action="${ctx }/post/insert">  
    <c:if test="${!empty post}">
  	  <input type="hidden" value="${post.id }" name="id">
  	  <input type="hidden" value="${post.typeId }" id="tId">
    </c:if>	
    <div class="form-group">
        <div class="label">
          <label>文章类别名称：</label>
        </div>
        <div class="field">
           <select name="typeId"  class="input w50" id="typeId">
              	
            </select>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>文章标题：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" required value="${post.title }" name="title" data-validate="required:文章标题,length#<=60:不能大于20个文字" />
          <div class="tips"></div>
        </div>
      </div>
      <%-- <div class="form-group">
        <div class="label">
          <label>文章作者：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" required value="${post.author }" name="author" data-validate="required:文章作者" />
          <div class="tips"></div>
        </div>
      </div> --%>
      <div class="form-group">
        <div class="label">
          <label>文章内容：</label>
        </div>
        <div class="field">
          <%-- <textarea  name="content" data-validate="required:文章内容">${post.content }</textarea> --%>
           <textarea  id="myEditor" name="content" style="width:100%;height:50%">
   				${post.content}
			</textarea>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit">
            <c:if test="${!empty post}">
            	修改
        	</c:if>
         	 <c:if test="${empty post}">
         	 	增加
         	 </c:if>
           </button>
        </div>
      </div>
    </form>
  </div>
</div>
 <script type="text/javascript">
	 //实例化编辑器
	 var um = UM.getEditor('myEditor');
</script>
</body></html>